package routes

import (
	"rego-top/controllers"
	"rego-top/dto"
	"rego-top/middleware"

	"github.com/gin-gonic/gin"
)

func SetupAuthRoutes(router *gin.RouterGroup) {
	authController := controllers.NewAuthController()

	// 公开路由（不需要认证）
	public := router.Group("/auth")
	{
		// 用户注册
		public.POST("/register", 
			middleware.ValidateJSON(&dto.RegisterRequest{}),
			authController.Register,
		)

		// 用户登录
		public.POST("/login", 
			middleware.ValidateJSON(&dto.LoginRequest{}),
			authController.Login,
		)

		// 刷新令牌
		public.POST("/refresh", 
			middleware.ValidateJSON(&dto.RefreshTokenRequest{}),
			authController.RefreshToken,
		)

		// 邮箱验证
		public.GET("/verify-email", authController.VerifyEmail)

		// 重新发送验证邮件
		public.POST("/resend-verification", authController.ResendVerificationEmail)

		// 忘记密码
		public.POST("/forgot-password", 
			middleware.ValidateJSON(&dto.ForgotPasswordRequest{}),
			authController.ForgotPassword,
		)

		// 重置密码
		public.POST("/reset-password", 
			middleware.ValidateJSON(&dto.ResetPasswordRequest{}),
			authController.ResetPassword,
		)
	}

	// 需要认证的路由
	protected := router.Group("/auth")
	protected.Use(middleware.AuthMiddleware())
	{
		// 获取用户资料
		protected.GET("/profile", authController.GetProfile)

		// 修改密码
		protected.POST("/change-password", 
			middleware.ValidateJSON(&dto.ChangePasswordRequest{}),
			authController.ChangePassword,
		)

		// 用户登出
		protected.POST("/logout", authController.Logout)
	}
}